/*
 * Adder.cpp
 *
 *  Created on: 2012-5-18
 *      Author: WuyaMony
 */

#include "Adder.h"

namespace my {
my::Adder::Adder(deque<int> &data) :
		_data(data),taskNum(0){
	t.isCalc = false;
	for (int i = 0; i < 3; ++i) {
		_calc.push_back(t);
	}
}

void my::Adder::addTask(int a, int b) {
	taskNum++;
	t.isCalc = true;
	t.a = a;
	t.b = b;
	cout<<"add task"<<t.a<<","<<t.b<<endl;
}

void my::Adder::Tick() {
//	cout<<t.a<<","<<t.b<<endl;
	_calc.push_back(t);
	t.isCalc = false;
	Task &tmp = _calc.front();
	if (tmp.isCalc) {
		_data.push_back(tmp.a + tmp.b);
		taskNum--;
	}
	_calc.pop_front();
}

}

